package com.study.order.provider;

import com.study.order.entity.Order;
import com.study.order.feign.OpenFeign;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

/**
 * @author yuanqj
 * @date 2021/01/27
 **/
@RefreshScope
@RestController
@RequestMapping("order")
public class OrderTest {

    @Autowired
    private OpenFeign openFeign;
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Value("${user.name}")
    private String name;

    @GetMapping(value = "/config")
    public String testConfig() {
        return name;
    }

    @GetMapping(value = "/{string}")
    public String echo(@PathVariable String string) {
        return "Hello Nacos Discovery " + string;
    }

    @GetMapping(value = "/test/{string}")
    public String openFeignTest(@PathVariable String string) {
        return openFeign.productTest(string);
    }


    @PostMapping(value = "/test/rabbitmq")
    public String testSendMQ() {
        Order order = new Order();
        order.setId("123456");
        order.setName("试一试");
        rabbitTemplate.convertAndSend("order-exchange", "order-key", order);
        return "";
    }

}
